home *** CD-ROM | disk | FTP | other *** search
/ Asymetrix Multimedia Toolbook 4.0 (CBT Edition) / Asymetric Multimedia Toolbook 4.0 (CBT Edition).iso / ctb40mt.z / PARADOX.ATS < prev    next >
Text File  |  1995-11-13  |  21KB  |  694 lines

  1. SCRIPT    "Link to Paradox"
  2. BEHAVIOR    "Link all the functions in the Asymetrix library TB40PDX.DLL. This library 'wraps' the Paradox Engine."
  3. CATEGORY Paradox
  4. {
  5. to handle linkPX
  6.     linkDLL sysToolBookDirectory & "tb40PDX.DLL"
  7.         INT addPXKey(STRING,STRING,INT)                --PXKeyAdd()
  8.         INT addPXPassword(STRING)                    --PXPswAdd()
  9.         INT addPXTable(STRING,STRING)                --PXTblAdd()
  10.         INT appendPXRecord(STRING)                    --PXRecAppend()
  11.         INT clonePXBlob(STRING,STRING)                --PXBlobClone()
  12.         INT closePXBitmapWindow(WORD)
  13.         INT closePXBlob(INT,INT)                    --PXBlobClose()
  14.         INT closePXTable(STRING)                    --PXTblClose()
  15.         INT copyPXTable(STRING,STRING)                --PXTblCopy()
  16.         INT createPXTable(STRING,STRING,STRING)        --PXTblCreate()
  17.         INT decryptPXTable(STRING)                    --PXTblDecrypt()
  18.         INT deletePXPassword(STRING)                --PXPswDel()
  19.         INT deletePXRecord(STRING)                    --PXRecDelete()
  20.         INT deletePXTable(STRING)                    --PXTblDelete()
  21.         INT doesPXTableExist(STRING)                --PXTblExist()
  22.         INT dropPXBlob(STRING,STRING)                --PXBlobDrop()
  23.         INT dropPXKey(STRING,STRING,WORD)            --PXKeyDrop()
  24.         INT emptyPXField(STRING,STRING)
  25.         INT emptyPXRecord(STRING)                    --PXRecBufEmpty()
  26.         INT emptyPXTable(STRING)                    --PXTblEmpty()
  27.         INT encryptPXTable(STRING,STRING)            --PXTblEncrypt()
  28.         INT exitPX()                                --PXExit()
  29.         INT freePXGraphicBlob(WORD)
  30.         INT freePXGraphicBlobPalette(WORD)
  31.         INT firstPXRecord(STRING)                    --PXRecFirst()
  32.         LONG getPXBitmapSize(WORD)
  33.         LONG getPXBlob(INT,DWORD,LONG)                --PXBlobGet()
  34.         LONG getPXBlobQuick(STRING,STRING,INT)        --PXBlobQuickGet()
  35.         LONG getPXBlobSize(INT)                        --PXBlobGetSize()
  36.         STRING getPXErrorString(INT)                --return error string
  37.         INT getPXFieldCount(STRING)                    --PXRecNFlds()
  38.         STRING getPXFieldNames(STRING)
  39.         STRING getPXFieldType(STRING,STRING)        --PXFldType()
  40.         STRING getPXFieldValue(STRING,STRING)
  41.         LONG getPXFileSize(STRING)
  42.         LONG getPXGraphicBlob(INT)
  43.         LONG getPXGraphicBlobPalette(INT)
  44.         INT getPXKeyFieldCount(STRING)                --PXKeyNFlds()
  45.         INT getPXMaxFiles()
  46.         INT getPXMaxLocks()
  47.         INT getPXMaxTables()
  48.         INT    getPXSwapSizeFromINI()
  49.         INT    getPXMaxTablesFromINI()
  50.         INT    getPXMaxFilesFromINI()
  51.         INT    getPXMaxLocksFromINI()
  52.         STRING getPXMemoBlob(INT)
  53.         STRING getPXNetErrorUser()                    --PXNetErrUser()
  54.         STRING getPXNetUserName()                    --PXNetUserName()
  55.         LONG getPXRaw(STRING,INT)                    --PXRawGet()
  56.         INT getPXRawDataSize(STRING)
  57.         LONG getPXRecordCount(STRING)                --PXTblNRecs()
  58.         LONG getPXRecordNumber(STRING)                --PXRecNum()
  59.         STRING getPXSortOrder()
  60.         INT getPXSwapSize()
  61.         STRING getPXUserInfo()
  62.         INT gotoPXNetRecordLock(STRING,INT)            --PXNetRecGotoLock()
  63.         INT gotoPXRecord(STRING,LONG)                --PXRecGoto()
  64.         INT initializePX(STRING)                    --PXWinInit()
  65.         INT insertPXRecord(STRING)                    --PXRecInsert()
  66.         INT isPXNetRecordLocked(STRING)                --PXNetRecLocked()
  67.         INT isPXNetTableChanged(STRING)                --PXNetTblChanged()
  68.         INT isPXTableProtected(STRING)                --PXTblProtected()
  69.         INT lastPXRecord(STRING)                    --PXRecLast()
  70.         INT lockPXNetFile(STRING,INT)                --PXNetFileLock()
  71.         LONG lockPXNetRecord(STRING)                --PXNetRecLock()
  72.         INT lockPXNetTable(STRING,INT)                --PXNetTblLock()
  73.         LONG mapPXKey(STRING,STRING,STRING,INT)        --PXKeyMap()
  74.         INT nextPXRecord(STRING)                    --PXRecNext()
  75.         LONG openPXBitmapWindow(WORD,WORD,WORD,STRING,INT,STRING)
  76.         LONG openPXBlobRead(STRING,STRING)            --PXBlobOpenRead()
  77.         LONG openPXBlobWrite(STRING,STRING,LONG,INT)--PXBlobOpenWrite()
  78.         INT openPXTable(STRING,STRING,INT,INT)        --PXTblOpen()
  79.         INT packPXTable(STRING)
  80.         INT previousPXRecord(STRING)                --PXRecPrev()
  81.         STRING queryPXKey(STRING)                    --PXKeyQuery()
  82.         INT refreshPXNetTable(STRING)                --PXNetTblRefresh()
  83.         INT renamePXTable(STRING,STRING)            --PXTblRename()
  84.         INT savePX()                                --PXSave()
  85.         INT searchPXField(STRING,STRING,WORD,INT)    
  86.         INT searchPXKey(STRING,INT,STRING,INT)        --PXSrchKey()
  87.         INT setPXBitmapWindowInfo(WORD,WORD,WORD,INT,STRING)
  88.         INT setPXBlob(INT,DWORD,LONG,WORD)            --PXBlobPut()
  89.         INT setPXBlobFromFile(INT,DWORD,DWORD,DWORD,STRING)--PXBlobPut()
  90.         INT setPXFieldValue(STRING,STRING,STRING)    --PXPutAlpha(), PXPutDate(), 
  91.                                                     --PXPutDouble(), PXPutLong(), PXPutShort()
  92.         INT    setPXGraphicBlob(INT,WORD,WORD)            --PXBlobPut()
  93.         INT setPXGraphicBlobFromFile(INT,STRING)    --PXBlobPut()
  94.         INT setPXINIMaxFiles(INT)                    --PXSetDefaults()
  95.         INT setPXINIMaxLocks(INT)                    --PXSetDefaults()
  96.         INT setPXINIMaxTables(INT)                    --PXSetDefaults()
  97.         INT setPXMemoBlob(INT,STRING)                --PXBlobPut()
  98.         INT setPXRaw(STRING,INT,INT)                --PXRawPut()
  99.         INT setPXSortOrder(STRING)
  100.         INT setPXINISwapSize(INT)
  101.         INT setPXTableCreateMode(INT)                --PXTblCreateMode()
  102.         INT setPXTableMaxSize(INT)                    --PXTblMaxSize()
  103.         INT setPXUserInfo(STRING)
  104.         INT unlockPXNetFile(STRING,INT)                --PXNetFileUnlock()
  105.         INT unlockPXNetRecord(STRING,INT)            --PXNetRecUnlock()
  106.         INT unlockPXNetTable(STRING,INT)            --PXNetTblUnlock()
  107.         INT updatePXRecord(STRING)                    --PXRecUpdate()
  108.         INT upgradePXTable(STRING)                    --PXTblUpgrade()
  109.         LONG writePXBlobToFile(INT,STRING,INT)        --PXBlobPut()
  110.         LONG writePXGraphicBlobToFile(INT,STRING,INT)--PXBlobPut()
  111.       end linkDLL
  112.       clear sysError
  113. end linkPX
  114. }
  115.  
  116. SCRIPT    "Initialize the Paradox engine"
  117. BEHAVIOR    "Initializes the Paradox Engine for Windows "
  118. CATEGORY    Paradox
  119. ARG    pxAlias    is    "myDBName"    help    "Can be set to an arbitrary name"
  120. {
  121. -- all "to get" handlers return the error code, calling handler must deal at that level
  122. -- do this first
  123. to get initPX $$pxAlias
  124.     return initializePX($$pxAlias)
  125. end    initPX
  126. }
  127.  
  128. SCRIPT    "Create a Paradox database"
  129. BEHAVIOR    "Creates a new database"
  130. CATEGORY    Paradox
  131. ARG    tName    is    "myDatabase" help "Name of new database without extension."
  132. {
  133. -- Pass fNameList and fTypeSize    from the calling handler. 
  134. -- fNameList will be a list of the names of the fields in the database
  135. -- fTypeSize will be a corresponding list of the types and sizes of those fields
  136. -- E.g. fNameList = "LastName,FirstName,Address";fTypeSize = "A15,A15,M10"
  137. to get createTable $$tName,fNameList,fTypeSize
  138.     if itemCount(fNameList) <> itemCount(fTypeSize)
  139.         request "Name list and type list for this database do not match. Please correct and try again."
  140.         return -1
  141.     end if
  142.        return createPXTable($$tName, fNameList, fTypeSize)
  143. end createTable
  144. }
  145.  
  146. SCRIPT    "Open a Paradox table"
  147. BEHAVIOR    "Opens a table with an index "
  148. CATEGORY    Paradox
  149. ARG    tBufType    oneof    "0,1"    is    "0"    help  "Work with buffer (0) or write straight to disk (1). Type 0 is prefered for performance."
  150. ARG    tIndex    is    "0"
  151. ARG    tName    is    "myDatabase"    help "The name the db file, without extension."
  152. ARG    tAlias    is    "myTable"
  153. {
  154. to get openTable  $$tAlias,$$tName
  155.     -- arbitrary alias.
  156.     -- the name the db file, without extension.
  157.     -- index id, 0 = PRIMARY.
  158.     -- work with buffer (0) or write straight to disk (1). Type 0 is prefered for performance
  159.     return  openPXTable($$tAlias,$$tName,$$tIndex,$$tBufType)
  160. end openTable
  161. }
  162.  
  163. SCRIPT    "Close a Paradox table"
  164. BEHAVIOR    "Closes a table "
  165. CATEGORY    Paradox
  166. ARG    tAlias    is    "myTable"
  167. {
  168. to get closeTable  $$tAlias
  169.     -- takes an alias to a table
  170.     return closePXTable($$tAlias)
  171. end closeTable
  172. }
  173.  
  174. SCRIPT    "Get the total number of records"
  175. BEHAVIOR    "Returns the toal number of records in a table "
  176. CATEGORY    Paradox
  177. ARG    tAlias    is    "myTable"
  178. {
  179. to get totalRecords $$tAlias
  180.     return getPXRecordCount($$tAlias)
  181. end
  182. }
  183.  
  184. SCRIPT    "Get the current record number"
  185. BEHAVIOR    "Returns the record number of the current record "
  186. CATEGORY    Paradox
  187. ARG    tAlias    is    "myTable"
  188. {
  189. to get currentRecord $$tAlias
  190.     return getPXRecordNumber($$tAlias)
  191. end    currentRecord
  192. }
  193.  
  194. SCRIPT    "Navigate to a record"
  195. BEHAVIOR    "Intelligently sets the current record "
  196. CATEGORY    Paradox
  197. ARG    tAlias    is    "myTable"
  198. {
  199. to set CurrentRecord  $$tAlias to value
  200.     clear sysError
  201.         conditions
  202.     when value is "next"
  203.         get nextPXRecord($$tAlias)
  204.     when value is "last"
  205.         get lastPXRecord($$tAlias)
  206.     when value is "previous"
  207.         get previousPXRecord($$tAlias)
  208.     when value is "first"
  209.         get firstPXRecord($$tAlias)
  210.     else
  211.         if isType(REAL, value) and (value > 0)
  212.             get gotoPXRecord($$tAlias,value)
  213.         else
  214.             request "Bad value trying to set current record."
  215.             break
  216.         end
  217.     end conditions
  218.  
  219.     conditions
  220.     when it = -101 -- start of table
  221.         get firstPXRecord($$tAlias)
  222.     when it = -102 -- end of table
  223.         get lastPXRecord($$tAlias)
  224.        end conditions
  225.  
  226.     if it < 0
  227.         request getPXErrorString(it)
  228.     end    if
  229. end currentRecord
  230. }
  231.  
  232. SCRIPT    "Get the value of a Paradox field"
  233. BEHAVIOR    "Gets the value for a field in the current record "
  234. CATEGORY    Paradox
  235. ARG    tAlias    is    "myTable"
  236. {
  237. to get fieldValue $$tAlias,fieldName
  238.     DBfieldType = getPXFieldType($$tAlias,fieldName)
  239.     clear SysError
  240.     retVal = -1 -- set return value to error, reset if value found
  241.     conditions
  242.     
  243.     -- memo "BLOB" (Binary Large OBject)
  244.     when first char of DBfieldType = "M"
  245.         hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
  246.         if hPrivateBlob < 0
  247.             retVal = hPrivateBlob
  248.         else
  249.             retVal = getPXMemoBlob(hPrivateBlob)
  250.             get closePXBlob(hPrivateBlob, 0)
  251.         end if
  252.         
  253.     -- graphics BLOB
  254.     when first Char of DBfieldType = "G"
  255.         hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
  256.         if hPrivateBlob < 0
  257.             retVal = hPrivateBlob
  258.         else
  259.             -- returns two items, 
  260.             -- handle to the bitmap and handle to the palette
  261.             retVal = getPXGraphicBlob(hPrivateBlob)
  262.             set item 2 of retVal to getPXGraphicBlobPalette(hPrivateBlob)
  263.             get closePXBlob(hPrivateBlob, 0)
  264.         end
  265.         
  266.     -- BLOB (the "B" stands for binary)
  267.     when first Char of DBfieldType = "B"
  268.         hPrivateBlob = openPXBlobRead($$tAlias, fieldName)
  269.         if hPrivateBlob < 0
  270.             send PXError hPrivateBlob
  271.         else
  272.             retVal = getPXBlob(hPrivateBlob, getBlobSize(hPrivateBlob), 0)
  273.             get closePXBlob(hPrivateBlob, 0)
  274.         end
  275.         
  276.     -- formatted text
  277.     when first Char of DBfieldType = "F"
  278.     -- debug
  279.         sysError = "This field type not supported: Formatted text"
  280.         
  281.     -- OLE BLOB
  282.     when first Char of DBfieldType = "O"
  283.         sysError = "This field type not supported: OLE Blob"
  284.         
  285.     -- all others
  286.     else
  287.         get getPXFieldValue($$tAlias,fieldName)    
  288.         retVal = it             
  289.     end
  290.     return retVal
  291. end
  292.  
  293. -- assuming a text field, called like this:
  294. -- to handle myUpdate
  295. --    get fieldValue(my name)
  296. --     if it < 0
  297. --        if it = -1
  298. --            request sysError
  299. --        else
  300. --            request getPXErrorString(it)
  301. --        end if
  302. --    else
  303. --         set my text to it
  304. --    end if
  305. -- end myUpdate
  306. }
  307.  
  308. SCRIPT    "Set the value of a field"
  309. BEHAVIOR    "Determines the data type for a field, then sets the value of that field "
  310. CATEGORY    Paradox
  311. ARG    tAlias    is    "myTable"
  312. {        
  313. to set fieldValue fieldName to value
  314.  
  315.     DBfieldType = getPXFieldType($$tAlias,fieldName)
  316.     clear sysError
  317.     pxErr = 1
  318.  
  319.     conditions
  320.     
  321.     -- memo BLOB
  322.     when first char of DBfieldType = "M"
  323.         BLOBSize = charCount(value) 
  324.              hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
  325.         if hPrivateBlob < 0
  326.             pxErr = hPrivateBlob
  327.         else
  328.             pxErr = setPXMemoBlob(hPrivateBlob, value)
  329.             get closePXBlob(hPrivateBlob, 1)
  330.         end if
  331.         
  332.     -- graphics BLOB from file        
  333.     when first char of DBfieldType = "G"
  334.         BLOBSize = getPXFileSize(value) + 8 -- for header
  335.         hPrivateBlob = openPXBlobWrite(DBTable of self, fieldName, BLOBSize, 0)
  336.         if hPrivateBlob < 0
  337.             pxErr = hPrivateBlob
  338.         else
  339.             pxErr =  setPXGraphicBlobFromFile(hPrivateBlob, value)
  340.             get closePXBlob(hPrivateBlob, 1)
  341.         end if
  342.         
  343.     -- binary BLOBs
  344.     when first char of DBfieldType = "B"
  345.         linkDLL "kernel"
  346.             WORD globalAlloc(WORD,DWORD)
  347.             POINTER globalLock(WORD)
  348.             WORD globalUnlock(WORD)
  349.             WORD globalFree(WORD)
  350.         end linkDLL
  351.  
  352.         BLOBSize = charCount(value) 
  353.          hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
  354.         if hPrivateBlob < 0
  355.             pxErr = hPrivateBlob
  356.  
  357.         -- how you deal with this next step depends a lot on what kind
  358.         -- of data you are using. For this example, we are assuming a "/0" 
  359.         -- terminated string (normal Windows string). At the other extreme,
  360.         -- you could place the data in the buffer stepping a byte at a time through
  361.         -- value using "step" and "pointerByte". Your solution will likely 
  362.         -- be somewhere in the middle.
  363.         else
  364.             -- 66 is the type of memory: initialized to zero, movable
  365.             hVal = globalAlloc(66,BLOBSize) 
  366.             -- create a pointer
  367.             pVal = globalLock(hVal)     
  368.             -- place the data into memory
  369.             get pointerString(0,pVal,value)    
  370.             -- tell Paradox where to get the data
  371.             pxErr = setPXBlob(hPrivateBlob, BLOBSize, 0, pVal) 
  372.             -- clean up
  373.             get closePXBlob(hPrivateBlob, 1) 
  374.             get globalUnlock(hVal)
  375.             get globalFree(hVal)
  376.         end if
  377.     
  378.     -- formatted memo BLOB
  379.     when first char of DBfieldType = "F"
  380.         sysError = "This field type not supported: Formatted text"
  381.         
  382.     -- OLE BLOB
  383.     when first char of DBfieldType = "O"
  384.         sysError = "This field type not supported: OLE Blob"
  385.         
  386.     -- all other
  387.     else
  388.         pxErr = setPXfieldvalue(DBTable of self,fieldName, value)    
  389.        end conditions
  390.     if pxErr < 1
  391.         sysError = getPXErrorString(pxErr)
  392.     end if
  393. end fieldValue
  394. }
  395.  
  396. SCRIPT    "Set BLOB from a file"
  397. BEHAVIOR    "Set an arbitrary binary large object using a file as the source "
  398. CATEGORY    Paradox
  399. ARG    tAlias    is    "myTable"
  400. {
  401. to set BlobFromFile fieldName to fileName
  402.     BLOBSize = getPXFileSize(fileName)
  403.     -- "0" means new blob, not a local copy 
  404.     hPrivateBlob = openPXBlobWrite($$tAlias, fieldName, BLOBSize, 0)
  405.      if hPrivateBlob < 0
  406.          pxErr = hPrivateBlob
  407.     else
  408.         -- "0, 0" are the respective offsets for the file and blob.
  409.            pxErr = setPXBlobFromFile(hPrivateBlob, BLOBSize, 0, 0, fileName)
  410.            get closePXBlob(hPrivateBlob, 1)    
  411.     end if
  412.     if pxErr < 1
  413.         sysError = getPXErrorString(pxErr)
  414.     end if
  415. end BlobFromFile
  416. }
  417.  
  418. SCRIPT    "Add a key"
  419. BEHAVIOR    "Add an index to a Paradox table"
  420. CATEGORY    Paradox
  421. {
  422. to get addKey appName,newAlias,fieldName,mode
  423.     -- for case-sensitive, single-field indexes
  424.     -- returns errorCode
  425.     get openPXTable(newAlias,appName,0,0) -- open new table indexed to primary
  426.     if it < 0  -- not likely
  427.         return it
  428.     end if
  429.     
  430.     --    Mode for creating index
  431.     -- 0    Primary index (key)
  432.     -- 1    Secondary index (maintained only when open)
  433.     -- 2    Incremental Secondary index (maintained even if closed)
  434.     if mode = NULL
  435.         set mode to 2 -- safest
  436.     end if
  437.     get addPXKey(newAlias,fieldName,mode) 
  438.     if it < 0
  439.         return it
  440.     end if
  441.     
  442.     get closeTable(newAlias) 
  443.     return it
  444. end addKey
  445. }
  446.  
  447. SCRIPT    "Add a compound key"
  448. BEHAVIOR    "Add a case-insensitive or compound-field key (index)"
  449. CATEGORY    Paradox
  450. {
  451. to get addCompoundKey appName,newAlias,fieldList,mode,keyName
  452.     -- for case-insensitive or compound-field indexes
  453.     -- returns PX-assigned number for the index, or error code
  454.     get openPXTable(newAlias,appName,0,0)
  455.     if it < 0
  456.         return it
  457.     end if
  458.     
  459.     -- 1 = case insensitive or compound
  460.     fieldNumber = mapPXKey(newAlias,fieldList,keyName,1) 
  461.     if fieldNumber < 0
  462.         return fieldNumber
  463.     end if
  464.  
  465.     if mode = NULL
  466.         set mode to 2 -- safest
  467.     end if
  468.  
  469.     get addPXKey(newAlias,keyName,mode)    
  470.     if it < 0
  471.         return it
  472.     end if
  473.  
  474.     get closePXTable(newAlias)    
  475.     if it < 0
  476.         return it
  477.     end if
  478.     
  479.     return fieldNumber
  480.     
  481.     -- now open the table from the calling handler                
  482.     --    get openPXTable(newAlias, appName, fieldNumber, savemode)
  483.  
  484. end addCompoundKey
  485. }
  486.  
  487. SCRIPT    "Drop a Paradox key"
  488. BEHAVIOR    "Drop an key (index) for a particular field "
  489. CATEGORY    Paradox
  490. {
  491. to get dropKey alias,fieldName,appName,indexID
  492.     -- returns error code
  493.     -- table closed on this alias at return
  494.     get openPXTable(alias,appName,indexID,0)
  495.     if it < 0  -- impossible
  496.         return it
  497.     else
  498.         get dropPXKey(alias,fieldName,indexID) -- ref by name and indexID
  499.         if it < 0
  500.             retValue = it
  501.             get closePXTable(alias)
  502.             return retValue
  503.         else 
  504.             get closePXTable(alias)
  505.             return it
  506.         end if
  507.     end if 
  508. end dropKey
  509. }
  510.  
  511. SCRIPT    "Open a tb40pdx.dll bitmap window"
  512. BEHAVIOR    "Open a bitmap window and display a graphic blob in it. "
  513. CATEGORY    Paradox
  514. ARG    hWndBitmap    is    "s_hWndBitmap"
  515. ARG    tFieldName    is    "Photo"
  516. ARG    tAlias    is    "myTable"
  517. {
  518. to get openBitmapWindow
  519.     system $$hWndBitmap
  520.     -- This will open a window and show the graphic blob in it
  521.     -- $$hWndBitmap is the handle to a window you're creating,
  522.     hPrivateBlob = openPXBlobRead("$$tAlias", "$$tFieldName")
  523.     if hPrivateBlob < 0
  524.         return hPrivateBlob
  525.     else
  526.         hBitmap = getPXGraphicBlob(hPrivateBlob)
  527.         hPalette = getPXGraphicBlobPalette(hPrivateBlob)
  528.         get closePXBlob(hPrivateBlob, 0)
  529.     end if
  530.     -- "2" = center the bitmap over the target
  531.     $$hWndBitmap = openPXBitmapWindowInfo(hBitmap, hPalette, 2, rgbFill of this page)
  532.     if $$hWndBitmap < 0
  533.         return getPXErrorString($$hWndBitmap)
  534.     end if
  535.     return "SUCCESS"
  536. end openBitmapWindow
  537. }
  538.  
  539. SCRIPT    "Set Bitmap Info"
  540. BEHAVIOR    "In an already created window, set the bitmap and/or palette "
  541. CATEGORY    Paradox
  542. ARG    hWndBitmap    is    "s_hWndBitmap"
  543. ARG    tAlias    is    "myTable"
  544. {
  545. to set PXBitmapWindowInfo to BMPField
  546.     -- this will show the graphic blob in a window
  547.     -- hWndBitmap is a handle to a window you've already created,
  548.     -- possibly with openPXBitmapWindow()
  549.     system $$hWndBitmap
  550.     hPrivateBlob = openPXBlobRead($$tAlias, BMPField)
  551.     if hPrivateBlob < 0
  552.         request getPXErrorString(hPrivateBlob)
  553.      else
  554.         hBitmap = getPXGraphicBlob(hPrivateBlob)
  555.         hPalette = getPXGraphicBlobPalette(hPrivateBlob)
  556.         get closePXBlob(hPrivateBlob, 0)
  557.         -- "2" = center the bitmap over the target
  558.         pxErr = setPXBitmapWindowInfo($$hWndBitmap, hBitmap, hPalette, 2, rgbFill of this page)
  559.         if pxErr < 0
  560.             request getPXErrorString(pxErr)
  561.         end if
  562.     end if
  563. end PXBitmapWindowInfo    
  564. }
  565.  
  566. SCRIPT    "Update record"
  567. BEHAVIOR    "Updates the current record in a table "
  568. CATEGORY    Paradox
  569. ARG    tAlias    is    "myTable"
  570. {
  571. to handle updateDB 
  572.      get updatePXRecord($$tAlias)
  573.     if it < 0
  574.         request getPXErrorString(it)
  575.     end
  576. end updateDB
  577. }
  578.  
  579. SCRIPT    "Update record to a table on the network"
  580. BEHAVIOR    "Updates the current record in a table that may be shared by other users "
  581. CATEGORY    Paradox
  582. ARG    tAlias    is    "myTable"
  583. {        
  584. to handle netUpdateDB
  585.     lockHandle = lockPXNetRecord($$tAlias)
  586.     conditions
  587.     -- we've got the lock
  588.     when lockHandle >= 0
  589.         clear sysError
  590.         get updatePXRecord($$tAlias)
  591.         if it < 0
  592.             request getPXErrorString(it)
  593.         end if        
  594.  
  595.     -- already locked
  596.     when lockHandle = -9
  597.         request "The record is locked by another user"
  598.  
  599.     -- disappeared
  600.     when lockHandle = -50
  601.         request "The record has been deleted by another user. Do you want to insert it?" with "OK" or "Cancel"
  602.         if it = "OK"
  603.                get emptyPXRecord($$tAlias) -- clear recordBuffer
  604.             -- you will probably want to modify this to work with your app,
  605.             -- but the idea is to fill the buffer with the values ToolBook 
  606.             -- is currently displaying in its fields. 
  607.             step i from 1 to objects of this page
  608.                 set curOb to item i of objects of this page
  609.                 if object of curOb contains "field" -- fields and recordfields
  610.                     -- set recordBuffer to current info, name of field in db and tb are the same
  611.                     set fieldValue(name of curOb) to text of curOb
  612.                 end if
  613.             end step
  614.             get insertPXRecord($$tAlias) -- place current record buffer in db
  615.         end    if
  616.     else
  617.         request getPXErrorString(it)    
  618.     end conditions
  619.     get unlockPXNetRecord($$tAlias, lockHandle)
  620. end    netUpdateDB
  621. }
  622.  
  623. SCRIPT    "Insert an empty record"
  624. BEHAVIOR    "Inserts a record before the current record in a non-indexed table "
  625. CATEGORY    Paradox
  626. ARG    tAlias    is "myTable"
  627. {
  628. to get insertRecord
  629.     get emptyPXRecord($$tAlias)
  630.     if it < 0    -- should never happen
  631.         return it
  632.     end if
  633.     --Insert record before the current record in a non-indexed table
  634.     ask "Enter record number to insert before."
  635.     if it <> null
  636.         get gotoPXRecord($$tAlias, it)
  637.     end
  638.     return insertPXRecord($$tAlias)    
  639. end    insertRecord
  640. }
  641.  
  642. SCRIPT    "Append an empty record"
  643. BEHAVIOR    "Places a new record at the end of the table "
  644. CATEGORY    Paradox
  645. ARG    tAlias    is    "myTable"
  646. {
  647. to get appendRecord
  648.     get emptyPXRecord($$tAlias)
  649.     if it < 0     -- should never happen
  650.         return it
  651.     end if
  652.     -- returns an empty record. 
  653.     return appendPXRecord($$tAlias)
  654. end
  655. }
  656.  
  657. SCRIPT    "Delete a Paradox record"
  658. BEHAVIOR    "Deletes the current record "
  659. CATEGORY    Paradox
  660. ARG    tAlias    is    "myTable"
  661. {
  662. to get deleteRecord
  663.      return deletePXRecord($$tAlias)
  664. end deleteRecord
  665. }
  666.  
  667. SCRIPT    "Get Paradox field names"
  668. BEHAVIOR    "Returns the names of all the fields in a table "
  669. CATEGORY    Paradox
  670. ARG    tAlias    is    "myTable"
  671. {
  672. to get PXFieldNames
  673.      return getPXFieldNames($$tAlias)
  674. end PXFieldNames
  675. }
  676.  
  677. SCRIPT    "Get the Paradox field type"
  678. BEHAVIOR    "Returns the field type and size for a field in a table "
  679. CATEGORY    Paradox
  680. ARG    tAlias    is    "myTable"
  681. {
  682. to get PXFieldType fieldName
  683.     return getPXFieldType($$tAlias,fieldName)
  684. end PXFieldType
  685. }
  686.  
  687. SCRIPT    "Paradox error handler"
  688. BEHAVIOR    "Returns the error string for any Paradox error number "
  689. CATEGORY    Paradox
  690. {
  691. to handle PXError errVal
  692.     request getPXErrorString(errVal)
  693. end PXError
  694. }